package com.whh.permission.service.serviceImpl;

import com.whh.permission.dao.DeptDao;
import com.whh.permission.po.Dept;
import com.whh.permission.po.Node;
import com.whh.permission.service.DeptService;
import com.whh.permission.util.TreeBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
@Service
public class DeptServiceImpl implements DeptService {
    @Autowired
    private TreeBuilder treeBuilder;
    @Resource
    private DeptDao deptMapper;
    @Override
    public List<Dept> queryDeptAll() {
        return deptMapper.queryDeptAll();
    }

    @Override
    public void addDept(Dept dept) {
        deptMapper.addDept(dept);
    }

    @Override
    public Dept queryDeptByID(Integer id) {
        return deptMapper.queryDeptByID(id);
    }

    @Override
    public void updateDept(Dept dept) {
        deptMapper.updateDept(dept);
    }

    @Override
    public void deleteDeptById(Integer id) {
        deptMapper.deleteDeptById(id);
    }

    @Override
    public List<Node> queryDeptTree() {
        List<Node> nodes = deptMapper.queryDeptTree();
        treeBuilder.buildTree(nodes);
        return nodes;
    }
}
